/*******************************************************************************
 * Copyright (c) 2010 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package asmifer;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.googlecode.ssdutils.beanconverter.api.BeanConverter;
import com.googlecode.ssdutils.beanconverter.api.BeanConverterFactory;
import com.googlecode.ssdutils.beanconverter.factory.BeanConverterFactoryImpl;

import asmifer.entities.AddresseA;
import asmifer.entities.AddresseB;
import asmifer.entities.PeopleA;
import asmifer.entities.PeopleB;

/**
 * @author Sylvain Sicard
 * 
 */
public class ConverterTest implements BeanConverter<PeopleA, PeopleB> {

	public ConverterTest() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.ssdutils.beanconverter.services.BeanConverter#convert(java.lang.Object)
	 */
	public PeopleB convert(PeopleA peopleA) {
		PeopleB peopleB = new PeopleB();

		peopleB.setName(peopleA.getName());
		peopleB.setAge(peopleA.getAge());
		peopleB.setRate(peopleA.getRate());
		peopleB.setByteField(peopleA.getByteField());
		peopleB.setObjectArray(peopleA.getObjectArray());

		Map<String, String> map_A = peopleA.getMap_();
		Map<String, String> map_B = new HashMap<String, String>();
		for (Map.Entry<String, String> entry : map_A.entrySet()) {
			map_B.put(entry.getKey(), entry.getValue());
		}
		peopleB.setMap_(map_B);

		Collection<String> collection_A = peopleA.getCollection_();
		Collection<String> collection_B = new LinkedList<String>();
		for (String s : collection_A) {
			collection_B.add(s);
		}
		peopleB.setCollection_(collection_B);

		BeanConverterFactory<AddresseA, AddresseB> addresseAtoBConverterFactory = new BeanConverterFactoryImpl<AddresseA, AddresseB>();
		BeanConverter<AddresseA, AddresseB> addresseAtoBConverter = addresseAtoBConverterFactory
				.getConverter(AddresseA.class, AddresseB.class);
		AddresseB addresseB = addresseAtoBConverter.convert(peopleA
				.getAddresse());
		peopleB.setAddresse(addresseB);

		return peopleB;
	}

}
